import Vue from 'vue'
import VueRouter from 'vue-router'
//
import login from '../views/Login.vue'
import rankcaiping from '../components/houtai/yydishes.vue'
import rankhuiyuan from '../components/houtai/yymember.vue'
import store from '../store/index'
Vue.use(VueRouter)
//

const routes = [
  {
    path: '/login',
    name: 'login',
    component: login,
    meta: {
      isLogin: false
    }
  },
  {
    path: '/',
    component: login,
    meta: {
      isLogin: false
    }
  },
  // ------------------前台路由----------------------------------------
  {
    path: '/qindex',
    name: 'qindex1',
    component: () => import('../views/QIndex.vue'),
    meta: {
      isLogin: true
    },
    children: [
      {
        path: '/qindex',
        name: 'xuancai2',
        component: () => import('../components/qianTai/realTable.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/CZGL/addTable',
        name: 'addTable',
        component: () => import('../components/qianTai/addTable.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/DCGL/xuancai',
        name: 'xuancai',
        component: () => import('../components/qianTai/xuancai.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/DCGL/qrXiaDan',
        name: 'qrXiaDan',
        component: () => import('../components/qianTai/qrXiaDan.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/CZGL/realTable',
        name: 'realTable',
        component: () => import('../components/qianTai/realTable.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/HYGL/zhucehuiyuan',
        name: 'zhucehuiyuan',
        component: () => import('../components/qianTai/zhucehuiyuan.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/HYGL/chaxunhuiyuan',
        name: 'chaxunhuiyuan',
        component: () => import('../components/qianTai/chaxunhuiyuan.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/DDGL/dingDanChaXun',
        name: 'dingDanChaXun',
        component: () => import('../components/qianTai/dingDanChaXun.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/DDGL/selfInfo',
        name: 'selfInfo',
        component: () => import('../components/qianTai/selfInfo.vue'),
        meta: {
          isLogin: true
        }
      }
    ]
  },

  //----------------------------后台路由--------------------------------------
  {
    path: '/hindex',
    name: 'hindex',
    component: () => import('../views/HIndex.vue'),
    meta: {
      isLogin: true
    },
    children: [
      { // -------------------------------------------这里是菜品管理
        path: '/hindex/cpSet', //菜品设置
        name: 'cpset',
        component: () => import('../components/houtai/cpSet.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/hindex/cpType', //菜品类型
        name: 'cptype',
        component: () => import('../components/houtai/cpType.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/hindex', //默认进入菜品设置
        name: 'cpSet',
        component: () => import('../components/houtai/cpSet.vue'),
        meta: {
          isLogin: true
        }
      },
      //这里是库存管理路由
      {
        path: '/hindex/xhSet',
        name: 'XHset',
        component: () => import('../components/houtai/XHset.vue')
      },
      {
        path: '/hindex/xhType',
        name: 'XHtype',
        component: () => import('../components/houtai/XHtype.vue')
      },
      { // -------------------------------------------这里是基础信息管理
        path: '/hindex/qxSet', //权限管理
        name: 'qxSet',
        component: () => import('../components/houtai/hpQxSet.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/hindex/ygSet', //员工管理
        name: 'ygset',
        component: () => import('../components/houtai/hpYgset.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/hindex/zwSet', //职位管理
        name: 'zwset',
        component: () => import('../components/houtai/hpZwSet.vue'),
        meta: {
          isLogin: true
        }
      },
      {//----------------------------------------------------------这里是系统设置
        path: '/hindex/DataBackup',//数据备份
        name: 'DataBackup',
        component: () => import('../components/houtai/DataBackup.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/hindex/The_Log',//日志
        name: 'The_Log',
        component: () => import('../components/houtai/The_Log.vue'),
        meta: {
          isLogin: true
        }
      },
      {//----------------------------------------------------------这里是财务分析
        path: '/hindex/Financial',//财务管理
        name: 'Financial',
        component: () => import('../components/houtai/Financial.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/hindex/Cost',//成本管理
        name: 'Cost',
        component: () => import('../components/houtai/Cost.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/hindex/Wage',//工资管理
        name: 'Wage',
        component: () => import('../components/houtai/Wage.vue'),
        meta: {
          isLogin: true
        }
      },
      //---------------------------------------------------------运营管理
      {
        path: '/hindex/pbset',//排班管理
        name: 'pbset',
        component: () => import('../components/houtai/pbSet.vue')
      },
      {
        path: '/hindex/yyset',//运营管理
        name: 'yyset',
        component: () => import('../components/houtai/yySet.vue'),
        meta: {
          isLogin: true
        },

        children: [
          {
            path: '/hindex/yySet',
            components: {
              yydishes: rankcaiping,
              yymember: rankhuiyuan
            }
          }
        ]
      },
      {
        path: '/hindex/czset',//餐桌管理
        name: 'czSet',
        component: () => import('../components/houtai/czSet.vue'),
        meta: {
          isLogin: true
        }
      },
      {
        path: '/hindex/hySet',//餐桌管理
        name: 'hyset',
        component: () => import('../components/houtai/hySet.vue'),
        meta: {
          isLogin: true
        }
      },
    ]
  }
]

const router = new VueRouter({
  mode: 'hash',
  routes
})
// 全局守卫
router.beforeEach((to, from, next) => {
  // console.log(store.state.user.name)
  // console.log(to.meta.isLogin)
  if (to.meta.isLogin) { //是否需要登录
    if (store.state.user.name) {
      next()
    } else {
      alert('请登录')
      router.push('/login')
    }
  } else {
    next()
  }
})
export default router
